package de.bazinga.rotw.network.message;

import com.captiveimagination.jgn.message.Message;
import com.captiveimagination.jgn.message.type.CertifiedMessage;
import com.captiveimagination.jgn.message.type.PlayerMessage;
import com.captiveimagination.jgn.message.type.TimestampedMessage;

import de.bazinga.rotw.game.RotwGameState;
import de.bazinga.rotw.gameModes.CaptureTheZombie;
import de.bazinga.rotw.network.Server;

public class ZombieInfoMessage extends Message implements CertifiedMessage, PlayerMessage, TimestampedMessage, GameMessage {	
	public static final int ZOMBIE_CAUGHT = 0;
	public static final int ZOMBIE_LOST = 1;
	public static final int ZOMBIE_SCORED = 2;
	
	
	private int zombieIndex = 1;
	private int zombieInfo = 0;
	

	public int getZombieInfo() {
		return zombieInfo;
	}

	public void setZombieInfo(int zombieInfo) {
		this.zombieInfo = zombieInfo;
	}

	public int getZombieIndex() {
		return zombieIndex;
	}

	public void setZombieIndex(int zombieIndex) {
		this.zombieIndex = zombieIndex;
	}

	
	public void handleMessage(RotwGameState game, Message msg, boolean server) {
		if(!(msg instanceof ZombieInfoMessage)) return ;

		// Player touched a item
		ZombieInfoMessage message = (ZombieInfoMessage)msg;
		
		if(server) {
			((CaptureTheZombie)game.getGameMode())
				.getZombie(message.getZombieIndex())
					.handleMessage(message);
		
			// Redirect to other clients
			((Server)game.getSyncManager()).getServer()
				.sendToAllExcept((ZombieInfoMessage)message, message.getPlayerId());
		}else{
			((CaptureTheZombie)game.getGameMode()).getZombie(message.getZombieIndex()).handleMessage(message);
		}
	}
}